﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Data.OleDb;
using System.IO;

namespace MikroTransfer
{
    public partial class frmHavaleEslestirme : XtraForm
    {
        public frmHavaleEslestirme()
        {
            InitializeComponent();
        }

        private void frmHavaleEslestirme_Load(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("No", typeof(string));
            dt.Columns.Add("İşlem Adı", typeof(string));
            dt.Columns.Add("Kasa Kodu", typeof(string));
            dt.Columns.Add("Banka Kodu", typeof(string));
            dt.Columns.Add("Banka Kodu (M1-XX)", typeof(string));
            dt.Columns.Add("Masraf/Cari Kodu", typeof(string));
            dt.Columns.Add("M1-XX Srm. Kodu", typeof(string));
            dt.Columns.Add("Açıklama Koşulu", typeof(string));

            if (File.Exists(Application.StartupPath + "\\banka_eslestirme.txt"))
            {
                using (StreamReader sr = new StreamReader(Application.StartupPath + "\\banka_eslestirme.txt"))
                {
                    string[] alanlar = null;
                    while (sr.Peek() > -1)
                    {
                        alanlar = sr.ReadLine().Split(';');
                        dt.Rows.Add(alanlar[0], alanlar[1], alanlar[2], alanlar[3], alanlar[4], alanlar[5], alanlar[6], alanlar[7]);
                    }
                    sr.Close();
                }
            }

            if (dt.Rows.Count == 0)
            {
                dt.Rows.Add("1", "AKBANK", "", "", "", "", "", "");
                dt.Rows.Add("2", "AKBANK DİJİTAL", "", "", "", "", "", "");
                dt.Rows.Add("3", "BANK ASYA", "", "", "", "", "", "");
                dt.Rows.Add("4", "FİNANSBANK", "", "", "", "", "", "13055953");
                dt.Rows.Add("5", "HSBC BANK", "", "", "", "", "", "062103904428200");
                dt.Rows.Add("6", "İŞ BANKASI", "", "", "", "", "", "TR540006400000143960008661");
                dt.Rows.Add("7", "TEB", "", "", "", "", "", "TR83 0006 2000 0820 0006 2969 30");
                dt.Rows.Add("8", "YKB", "", "", "", "", "", "TLSM093163882670DOPS");
                dt.Rows.Add("9", "YKB DİJİTAL", "", "", "", "", "", "TLSM093163882670DOPS");
                dt.Rows.Add("11", "TEB-FORTİS", "", "", "", "", "", "ANAFARTALAR CADDESİ-30421");
            }

            gridControl1.DataSource = dt;
            gridView1.Columns[0].OptionsColumn.AllowEdit = false;
            gridView1.Columns[1].OptionsColumn.AllowEdit = false;
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            using (StreamWriter sw = new StreamWriter(Application.StartupPath + "\\banka_eslestirme.txt", false))
            {
                for (int i = 0; i < gridView1.RowCount; i++)
                {
                    if (!string.IsNullOrEmpty(gridView1.GetRowCellValue(i, gridView1.Columns[0]).ToString()) && !string.IsNullOrEmpty(gridView1.GetRowCellValue(i, gridView1.Columns[1]).ToString()))
                    {
                        sw.WriteLine(string.Format("{0};{1};{2};{3};{4};{5};{6};{7}", gridView1.GetRowCellValue(i, gridView1.Columns[0]).ToString(), gridView1.GetRowCellValue(i, gridView1.Columns[1]).ToString(), gridView1.GetRowCellValue(i, gridView1.Columns[2]).ToString(), gridView1.GetRowCellValue(i, gridView1.Columns[3]).ToString(),
                            gridView1.GetRowCellValue(i, gridView1.Columns[4]).ToString(), gridView1.GetRowCellValue(i, gridView1.Columns[5]).ToString(), gridView1.GetRowCellValue(i, gridView1.Columns[6]).ToString(), gridView1.GetRowCellValue(i, gridView1.Columns[7]).ToString()));
                    }
                }
                sw.Close();
            }
            this.Close();
        }
    }
}
